package com.yanqu.road.server.cmd.triggerwindow;

import com.yanqu.road.entity.triggerwindow.ActTriggerWindow;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.ActivityTriggerWindowProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.triggerwindow.ActTriggerWindowModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_GET_ACTIVITY_TRIGGER_WINDOW, desc = "请求获取活动弹窗触发记录")
public class ActTriggerWindowGetCmd extends AbstractCommand {
    private int activityId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        ActivityTriggerWindowProto.ActivityTriggerWindowGetDataReqMsg reqMsg = ActivityTriggerWindowProto.ActivityTriggerWindowGetDataReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ActTriggerWindow userData = player.getModule(ActTriggerWindowModule.class).getActRecordList();
        if (userData == null) {
            ret = GameErrorCode.E_SYSTEM_NO_OPEN;
            return;
        }
        ret = player.getModule(ActTriggerWindowModule.class).getData(activityId);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            ActivityTriggerWindowProto.ActivityTriggerWindowGetDataRespMsg.Builder builder = ActivityTriggerWindowProto.ActivityTriggerWindowGetDataRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_GET_ACTIVITY_TRIGGER_WINDOW, builder);
        }
    }
}
